"""
Case Type   : show collation
Case Name   : 查看show_collation()函数返回是否正确
Create At   : 2024/10/25
Owner       : lonely-dance
Description :
    1.查看show collation()函数返回是否正确
    2.查看show collation()函数结合where使用
Expect      :
    1.成功
History     :
"""
import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class ShowCollation(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.pri_b_sh = CommonSH('PrimaryDbBmode')
        self.constant = Constant()

    def test_show_collation(self):
        text = '-----step1:查看show collation()函数返回是否正确 expect:查询成功-----'
        self.log.info(text)
        cmd1 = """
            select * from show_collation();
        """
        cmd2 = """
            select * from show_collation();
        """
        self.log.info(cmd1)
        self.log.info(cmd2)
        res1 = self.pri_b_sh.execut_db_sql(cmd1)
        res2 = self.pri_b_sh.execut_db_sql(cmd2)
        self.log.info(res1)
        self.log.info(res2)
        self.assertEqual(res1, res2, '执行失败' + text)

        text = '-----step2:查看show collation()函数结合where使用 expect:查询成功-----'
        self.log.info(text)
        cmd = """
            select * from show_collation() where "collation" = 'be_BY';
        """
        self.log.info(cmd)
        res = self.pri_b_sh.execut_db_sql(cmd)
        self.log.info(res)
        self.assertNotIn('ERROR', res, '执行失败' + text)

    def tearDown(self):
        self.log.info(f'----{os.path.basename(__file__)} end----')
